package com.erp.hr.base.vo;

import lombok.Data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class ResultVO<T> implements Serializable {

	private static final long serialVersionUID = 4560633801107550600L;

	public static int SUCCESS = 1;

	public static int ERROR = 2;

	private int code;

	private String msg;

	private T data;

	public static Map<Integer, String> errors = new HashMap<Integer, String>();

	static {
		errors.put(SUCCESS, "成功");
		errors.put(ERROR, "失败");
	}

	public static <T> ResultVO<T> error(T data, int code, String msg){
		ResultVO<T> result = new ResultVO<T>(code, msg);
		result.setData(data);
		return result;
	}

	public static <T> ResultVO<T> error(String msg){
		ResultVO<T> result = new ResultVO<T>(ResultVO.ERROR, msg);
		return result;
	}

	public static <T> ResultVO<T> error(int code, String msg){
		ResultVO<T> result = new ResultVO<T>(code, msg);
		return result;
	}

	public static <T> ResultVO<T> success(T data, int code, String msg){
		ResultVO<T> result = new ResultVO<T>(code, msg);
		result.setData(data);
		return result;
	}

	public static <T> ResultVO<T> success(int code, String msg){
		ResultVO<T> result = new ResultVO<T>(code, msg);
		return result;
	}

	public static <T> ResultVO<T> success(String msg){
		ResultVO<T> result = new ResultVO<T>(ResultVO.SUCCESS, msg);
		return result;
	}

	public static <T> ResultVO<T> success(){
		ResultVO<T> result = new ResultVO<T>(ResultVO.SUCCESS, ResultVO.errors.get(ResultVO.SUCCESS));
		return result;
	}

	public ResultVO() {}

	public ResultVO(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

}